#include "perfor.h"

void perfor(int lcdp[][800])
{
	int i, j;
	int color[6] = {b, r, p, ye, bl, g};
	for (i = 0; i < 480; i++)
	{
		for (j = 0; j < 800; j++)
		{
			if (j == 750)
				lcdp[i][j] = b;
			else
				lcdp[i][j] = w;
		}
	}
	for (i = 25; i < 125; i++) // 尺寸滑块条
		lcdp[i][775] = 0;
	int rx = 775, ry = 25; // 圆心1 r=4|8
	for (i = 0; i < 480; i++)
		for (j = 750; j < 800; j++)
		{
			if ((j - rx) * (j - rx) + (i - ry) * (i - ry) == 16)
				lcdp[i][j] = b;
			else if ((j - rx) * (j - rx) + (i - ry) * (i - ry) < 16)
				lcdp[i][j] = b;
		}
	ry = 125; // 圆心3
	for (i = 0; i < 480; i++)
		for (j = 750; j < 800; j++)
		{
			if ((j - rx) * (j - rx) + (i - ry) * (i - ry) == 64)
				lcdp[i][j] = b;
			else if ((j - rx) * (j - rx) + (i - ry) * (i - ry) < 64)
				lcdp[i][j] = b;
		}
	ry = 140; // y:140-290 颜色选择滑块条
	int count = 0, choose = 0;
	for (i = 140; i < 290; i++)
	{
		if (count == 25)
		{
			choose = (++choose) % 6;
			count = 0;
		}
		else
			count++;
		for (j = 760; j < 790; j++)
		{
			lcdp[i][j] = color[choose];
		}
	}
	unsigned char buf1[60][40 * 3] = {0}; // 橡皮擦区域
	unsigned char buf2[60][40 * 3] = {0};
	unsigned char buf3[60][40 * 3] = {0};
	FILE *pic1 = fopen("./res/rubber.bmp", "r");
	FILE *pic2 = fopen("./res/save.bmp", "r");
	FILE *pic3 = fopen("./res/clear.bmp", "r");
	if (pic1 == NULL || pic2 == NULL || pic3 == NULL)
	{
		perror("pic open fail\n");
		return;
	}
	fseek(pic1, 54, SEEK_SET);
	fseek(pic2, 54, SEEK_SET);
	fseek(pic3, 54, SEEK_SET);
	fread(buf1, 3, 60 * 40, pic1);
	fread(buf2, 3, 60 * 40, pic2);
	fread(buf3, 3, 60 * 40, pic3);
	for (i = 0; i < 60; i++)
		for (j = 0; j < 40; j++)
		{
			int x = 755 + j;
			int y = 360 - i;
			lcdp[y][x] = 0x00 << 24 | buf1[i][j * 3 + 2] << 16 | buf1[i][j * 3 + 1] << 8 | buf1[i][j * 3] << 0;
		}
	for (i = 0; i < 60; i++)
		for (j = 0; j < 40; j++)
		{
			int x = 755 + j;
			int y = 420 - i;
			lcdp[y][x] = 0x00 << 24 | buf2[i][j * 3 + 2] << 16 | buf2[i][j * 3 + 1] << 8 | buf2[i][j * 3] << 0;
		}
	for (i = 0; i < 60; i++)
		for (j = 0; j < 40; j++)
		{
			int x = 755 + j;
			int y = 479 - i;
			lcdp[y][x] = 0x00 << 24 | buf3[i][j * 3 + 2] << 16 | buf3[i][j * 3 + 1] << 8 | buf3[i][j * 3] << 0;
		}
}